// KnowledgeModuleServiceImpl.java - 完整实现类
package com.example.gymlearning.service.impl;

import com.example.gymlearning.entity.KnowledgeModule;
import com.example.gymlearning.mapper.KnowledgeModuleMapper;
import com.example.gymlearning.service.KnowledgeModuleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("knowledgeModuleService")
public class KnowledgeModuleServiceImpl implements KnowledgeModuleService {

    @Resource
    private KnowledgeModuleMapper knowledgeModuleMapper;

    @Override
    public KnowledgeModule queryById(Long id) {
        return this.knowledgeModuleMapper.queryById(id);
    }

    @Override
    public KnowledgeModule insert(KnowledgeModule knowledgeModule) {
        this.knowledgeModuleMapper.insert(knowledgeModule);
        return knowledgeModule;
    }

    @Override
    public KnowledgeModule update(KnowledgeModule knowledgeModule) {
        this.knowledgeModuleMapper.update(knowledgeModule);
        return this.queryById(knowledgeModule.getId());
    }

    @Override
    public boolean deleteById(Long id) {
        return this.knowledgeModuleMapper.deleteById(id) > 0;
    }

    @Override
    public List<KnowledgeModule> getAllModules() {
        return knowledgeModuleMapper.selectAll();
    }

    @Override
    public KnowledgeModule getModuleById(Long id) {
        return knowledgeModuleMapper.selectById(id);
    }

    // 添加缺失的方法实现
    @Override
    public List<KnowledgeModule> getModulesByClassId(Long classId) {
        // 需要在KnowledgeModuleMapper中添加此方法
        return knowledgeModuleMapper.selectByClassId(classId);
    }

    @Override
    public Page<KnowledgeModule> getModulesByClassIdWithPagination(Long classId, int page, int size) {
        PageHelper.startPage(page, size);
        List<KnowledgeModule> modules = knowledgeModuleMapper.selectByClassId(classId);
        return (Page<KnowledgeModule>) modules;
    }

    @Override
    public Long countByClassId(Long classId) {
        Long count = knowledgeModuleMapper.countByClassId(classId);
        return count == null ? 0L : count;
    }
}